package com.guragura.util;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;

/**
 * Manages all setting for this game
 * Mengatur vibrasi dan sound -> on / off
 * @author hartono
 * 
 */
public class GuraSettings {

	public static boolean vibration = false;
	public static boolean sound = false;

	/**
	 * method untuk meload settingan -> membungkus dua method lainnya, sehingga programmer cukup memanggil method ini saja
	 * 
	 */
	public static void loadSettings() {
		Preferences pref = Gdx.app.getPreferences("settings");
		if (pref != null) {
			if (!pref.getBoolean("setup")) {
				// first start
				
				resetDefaultSettings();
				loadSavedSettings();

			} else {
				// next start
				loadSavedSettings();
			}
		}
	}


	/**
	 * load setting yang uda pernah disave oleh user
	 */
	public static void loadSavedSettings() {
		Preferences pref = Gdx.app.getPreferences("settings");
		if (pref != null) {
			vibration = pref.getBoolean("vibration");
			sound = pref.getBoolean("sound");	
			
		}
	}

	/**
	 * Default setting -> sound on , vibration on
	 */
	public static void resetDefaultSettings() {
		Preferences pref = Gdx.app.getPreferences("settings");
		if (pref != null) {
			pref.putBoolean("setup", true);
			pref.putBoolean("sound", true);
			pref.putBoolean("vibration", true);			
		}

	}

	/**
	 * menyimpan isi dari variable {@link GuraSettings#sound dan GuraSettings#vibration} ke dalam
	 * {@link Preferences}
	 */
	public static void saveSettings() {
		Preferences pref = Gdx.app.getPreferences("settings");
		if (pref != null) {					
			pref.putBoolean("sound", sound);
			pref.putBoolean("vibration", vibration);			
		}
	}
}
